Hash Function











HASH FUNCTION

This hash function is expressed as:

For each bit (Ci) in the hash code (1 ≤ i ≤ n):

Ci = bi1 ⊕ bi2 ⊕ g ⊕ bim

where:

  • Ci: ith bit of the hash code
  • m: number of n-bit blocks in the input
  • bij: ith bit in jth block
  • : XOR operation

1. Initialize hash variable: Set hash to 0.

2. Iterate through each character in the input string:
• For each character in the input string:
• Get the ASCII code of the current character.

3. Perform XOR operation with the current character's ASCII code:
• Update the hash by performing XOR with the ASCII code of the current character.

4. Repeat for all characters:
• Continue this process for each character in the input string.

5. Convert the final hash value to a string:
• After processing all characters, convert the final hash value to a string.

6. Return the hashed value:
• The resulting string is the hashed value of the input.


Suppose we apply the provided hashing algorithm to the string "abc". The steps would be as follows:

1. The ASCII code for 'a' is 97.
* Initially, 'hash' is 0.
* Perform XOR operation: 'hash ^ 97' results in '97'.
* 'hash' is now updated to '97'.

2. The ASCII code for 'b' is 98.
* Perform XOR operation: '97 ^ 98' results in '3'.
* 'hash' is now updated to '3'.

3. The ASCII code for 'c' is 99.
* Perform XOR operation: '3 ^ 99' results in '96'.
* 'hash' is now updated to '96'.

In this way, if we hash the string "abc" using the algorithm, the resulting hashed value would be "96".